const express = require('express');
const router = express.Router();
const { auth } = require('../middlewares/auth');
const { healthDataValidator, healthReportValidator } = require('../middlewares/validators');
const healthDataController = require('../controllers/healthDataController');
const healthReportController = require('../controllers/healthReportController');
const upload = require('../middlewares/upload');

// 健康数据路由
// @route   POST /api/health/data
// @desc    添加健康数据
// @access  Private
router.post('/data', auth, healthDataValidator, healthDataController.addHealthData);

// @route   GET /api/health/data
// @desc    获取用户所有健康数据
// @access  Private
router.get('/data', auth, healthDataController.getUserHealthData);

// @route   GET /api/health/data/type/:type
// @desc    获取用户特定类型的健康数据
// @access  Private
router.get('/data/type/:type', auth, healthDataController.getUserHealthDataByType);

// @route   GET /api/health/data/:id
// @desc    根据ID获取健康数据
// @access  Private
router.get('/data/:id', auth, healthDataController.getHealthDataById);

// @route   PUT /api/health/data/:id
// @desc    更新健康数据
// @access  Private
router.put('/data/:id', auth, healthDataController.updateHealthData);

// @route   DELETE /api/health/data/:id
// @desc    删除健康数据
// @access  Private
router.delete('/data/:id', auth, healthDataController.deleteHealthData);

// 健康报告路由
// @route   POST /api/health/reports
// @desc    上传健康报告
// @access  Private
router.post('/reports', auth, upload.single('report'), healthReportValidator, healthReportController.uploadReport);

// @route   GET /api/health/reports
// @desc    获取用户所有健康报告
// @access  Private
router.get('/reports', auth, healthReportController.getUserReports);

// @route   GET /api/health/reports/:id
// @desc    根据ID获取健康报告
// @access  Private
router.get('/reports/:id', auth, healthReportController.getReportById);

// @route   PUT /api/health/reports/:id
// @desc    更新健康报告
// @access  Private
router.put('/reports/:id', auth, healthReportController.updateReport);

// @route   DELETE /api/health/reports/:id
// @desc    删除健康报告
// @access  Private
router.delete('/reports/:id', auth, healthReportController.deleteReport);

// @route   GET /api/health/reports/:id/download
// @desc    下载健康报告
// @access  Private
router.get('/reports/:id/download', auth, healthReportController.downloadReport);

module.exports = router; 